package cn.ecnu.user.mapper;

import cn.ecnu.user.pojo.User;
import cn.ecnu.user.vo.AdminUserVo;
import cn.ecnu.user.vo.RegisterWithUsernameVo;
import cn.ecnu.user.vo.UserInfoVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {

    int addUser(User user);

    @Update("delete FROM `user` WHERE user_id = #{uid}")
    int deleteUserById(@Param("uid") Integer uid);

    @Select("SELECT COUNT(*) FROM `user`")
    Integer getTotal();

    List<AdminUserVo> getAdminUserVoAll();

    @Update("UPDATE `user` SET username = #{username}, email = #{email} WHERE user_id = #{userId}")
    int updateUserVoById(UserInfoVo vo);

    @Select("SELECT * FROM `user` WHERE username = #{username} LIMIT 1")
    User getUserByUsername(@Param("username") String username);

    @Select("SELECT * FROM `user` WHERE email = #{email} LIMIT 1")
    User getUserByEmail(@Param("email") String email);

    @Select("SELECT * FROM `user` WHERE username = #{username} OR email = #{email} LIMIT 1")
    User getUserByUsernameOrEmail(RegisterWithUsernameVo vo);
}
